package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.Teacher;
import com.example.haoqisystem.request.CreateTeacherRequest;
import com.example.haoqisystem.request.UpdateTeacherRequest;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "讲师Api")
@RequiredArgsConstructor(onConstructor_ ={@Autowired} )
@RequestMapping("/teacher")
public class TeacherController {

    private final TeacherService teacherService;

    //查询教师列表

    @ApiOperation(value = "讲师新增")
    @PostMapping("/add")
    public BaseResponse<Teacher> teacherRegister(@RequestBody CreateTeacherRequest request){
        return teacherService.register(request);
    }

    @ApiOperation(value = "讲师登录（暂时不用)")
    @GetMapping("/login")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account",value = "账号"),
            @ApiImplicitParam(name = "password",value = "密码")
    })
    public BaseResponse<Teacher> login(String account,String password){
        return teacherService.login(account,password);
    }

    @ApiOperation(value = "修改讲师信息")
    @PutMapping("/update")
    public BaseResponse<Teacher> update(@RequestBody UpdateTeacherRequest request){
        return teacherService.update(request);
    }

    @ApiOperation(value = "查询讲师列表")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "讲师姓名"),
            @ApiImplicitParam(name = "jobTitle",value = "工作主题"),
            @ApiImplicitParam(name = "skillField",value = "技能领域"),
            @ApiImplicitParam(name = "id",value = "id",dataType = "Long")
    })
    public BaseResponse<List<Teacher>> queryList(String name,String jobTitle,String skillField,Long id){
        return teacherService.queryList(name,jobTitle,skillField,id);
    }

    @ApiOperation(value = "跟据id查询教师详情")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "教师id",required = true)
    })
    public BaseResponse<Teacher> detail(Long id){
        return teacherService.detail(id);
    }

    @ApiOperation(value = "删除教师")
    @GetMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "教师id",required = true)
    })
    public BaseResponse<String> delete(Long id){
        return teacherService.delete(id);
    }

    @ApiOperation(value = "更改密码")
    @GetMapping("/reset")
    public BaseResponse<String> resetPassword(@RequestParam("id") Long id,
                                              @RequestParam("password") String password){
        return teacherService.resetPassword(id,password);
    }
}

